#include <iostream>
#include <array>

using std::cout;
using std::endl;
using std::array;

// 使用回溯算法求解最优装在问题
static int tmp = 0;
static int remain = 35;

template<size_t N>
void func(array<int, N> &arr, int i, int c, int &max)
{
    if(i == N){
        if(tmp > max) max = tmp;
    }else{
        remain -= arr[i];
        if(tmp + arr[i] <= c){
            tmp += arr[i];
            func(arr, i + 1, c, max);
            tmp -= arr[i];
        }
        // 当前已选择的 加上未来能选择的大于max时才继续
        if(tmp + remain > max)
            func(arr, i + 1, c, max);
        remain += arr[i];
    }
}

int main(int args, char *argv[])
{
    array<int, 3> arr {12, 8, 15};
    int max = 0;
    func(arr, 0, 27, max); 
    cout << max << endl;
    return 0;
}